package com.future.mvc.web.hw;

import com.future.mvc.web.hw.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * <P>
 *
 * </p>
 *
 * @author yinhao
 * @version 1.0
 * @date 2024/9/4 17:54
 */
@Controller
@RequestMapping("/user")
public class LoginHandler {

    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/login")
    public String login(User user) {
        if ("admin".equals(user.getUsername()) && "123456".equals(user.getPassword())) {
            user.setPassword("");
            request.getSession().setAttribute("user", user);
            return "forward:/WEB-INF/pages/hw/login_ok.jsp";
        } else {
            return "forward:/WEB-INF/pages/hw/login_fail.jsp";
        }
    }
}
